package com.blockmeta.bbs.overallserviceapplication.search.adapter;

import android.content.Context;
import androidx.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ToggleButton;

import com.alibaba.android.arouter.facade.Postcard;
import com.blockmeta.bbs.baselibrary.base.adapter.BaseAdapter;
import com.blockmeta.bbs.baselibrary.utils.FormatUtil;
import com.blockmeta.bbs.baselibrary.utils.TimeUtil;
import com.blockmeta.bbs.businesslibrary.arouter.RouterHelper;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.businesslibrary.widget.CircleImageView;
import com.blockmeta.bbs.overallserviceapplication.R;
import com.blockmeta.bbs.overallserviceapplication.pojo.CollegeListPOJO;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by author on 2018/1/8.
 */

public class CollegeListAdapter extends BaseAdapter<CollegeListPOJO, BaseViewHolder> {
    private Context mContext;

    public CollegeListAdapter(int layoutResId, @Nullable List<CollegeListPOJO> data, Context context) {
        super(layoutResId, data);
        mContext = context;
    }


    @Override
    protected void convert(BaseViewHolder helper, final CollegeListPOJO item) {
        if (item.getPic() != null) {
            Glide.with(mContext).load(item.getPic()).placeholder(R.drawable.yoona).into((ImageView) helper.getView(R.id.item_news_type2_img));
        }
        helper.setText(R.id.item_news_type2_title, item.getTitle());
        CircleImageView cirImg = helper.getView(R.id.item_news_type2_from);
        Picasso.with(mContext).load(item.getAvatar_img()).placeholder(R.drawable.yoona).into(cirImg);

        final ImageView player = helper.getView(R.id.item_video_play);
        if ("video".equals(item.getCollege_type())) {
            player.setVisibility(View.VISIBLE);
        } else {
            player.setVisibility(View.GONE);
        }


        helper.setText(R.id.item_news_type2_time, TimeUtil.InforMationTime(FormatUtil.parseInt(item.getDateline())));

        helper.setText(R.id.item_news_type2_views, item.getViewnum());
        helper.setText(R.id.item_news_type2_reply, item.getCommentnum());
        ToggleButton toggleButton = helper.getView(R.id.tg_type2_selector);

        final LinearLayout main = helper.getView(R.id.item_news_type2_main);
        main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (item.getIdtype().equals("aid")) {
                    RouterHelper.startActivity(mContext, RouterPath.BBS_COLLEGE_DETAIL_ACTIVITY,item.getId());
                } else if (item.getIdtype().equals("news")) {
                    Postcard postcard = RouterHelper.buildPath(RouterPath.NEWS_INNER_DETAIL_ACTIVITY);
                    if (item.getPost_id() != null) {
                        postcard.withString(Constant.ONE, item.getPost_id());
                    } else {
                        postcard.withString(Constant.ZERO, item.getPost_name());
                    }
                    postcard.navigation(mContext);
                } else if (item.getIdtype().equals("bbs")) {
                    RouterHelper.buildPath(RouterPath.NEWS_INNER_DETAIL_ACTIVITY)
                            .withString("tid",item.getId())
                            .navigation(mContext);
                } else if (item.getIdtype().equals("allow")) {
                    RouterHelper.startActivity(mContext,RouterPath.WEB_ACTIVITY,item.getUrl(),"学院详情");
                }
            }
        });

    }
}
